$(document).ready(function() {
    var defaultStartLatitude = 50.447892;
    var defaultStartLongitude = 30.451584;
    var geocoder;
    var map;
    var directionsDisplay;
    var warehouses = $(".warehouse");

    function getLatitude(obj) {
        return $(obj).attr("latitude");
    }

    function getLogitude(obj) {
        return $(obj).attr("logitude");
    }

    function getName(obj) {
        return $(obj).attr("name");
    }

    function initialize() {
        directionsDisplay = new google.maps.DirectionsRenderer();
        geocoder = new google.maps.Geocoder();
        var mapOptions = {
            zoom: 9,
            center: new google.maps.LatLng(defaultStartLatitude, defaultStartLongitude),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        map = new google.maps.Map(document.getElementById('googmap'), mapOptions);
        directionsDisplay.setMap(map);


        if (warehouses.length != 0)
            map.setCenter(new google.maps.LatLng(getLatitude(warehouses[0]), getLogitude(warehouses[0])));

        for (var i = 0; i < warehouses.length; i++) {
            new google.maps.Marker({
                map: map,
                position: new google.maps.LatLng(getLatitude(warehouses[i]), getLogitude(warehouses[i])),
                dragable: false,
                icon: 'images/numbers/number_' + (i + 1) + '.png',
                animation: google.maps.Animation.DROP,
                title: getName(warehouses[i])
            });
        }

    }
    google.maps.event.addDomListener(window, 'load', initialize);

    warehouses.each(function() {
        var war = $(this);
        war.hover(function() {
//            cleanBackground();
//            war.css("background", "#ededed");
            map.setCenter(new google.maps.LatLng(getLatitude(war), getLogitude(war)));
        });
    });

//    function cleanBackground() {
//        warehouses.each(function() {
//            $(this).css("background", "#FFF");
//        });
//    }
});